public class MyQueue {
    static class ListNode {
        public int value;
        public ListNode next;

        public ListNode(int value) {
        }
    }
    public ListNode head;
    public ListNode last;
    private int usedSize = 0;
    //入队
    public void offer(int value) {
        ListNode newNode = new ListNode(value);
        if(head == null) {
            head = newNode;
            last = newNode;
            usedSize++;
            return;
        }
        last.next = newNode;
        last = newNode;
        usedSize++;
    }

    public int size() {
        return usedSize;
    }
    //出队
    public int poll() {
        if(head == null) {
            return -1;
        }
        if(head.next == null) {
            int val = head.value;
            head = null;
            last = null;
            usedSize = 0;
            return val;
        }
        int val = head.value;
        head = head.next;
        usedSize--;
        return val;
    }
    //查看队列第一个元素
    public int peek() {
        if(head == null) {
            return -1;
        }
        return head.value;
    }
}
